﻿#include <iostream>
#include <thread>
#include "SafeStack.h"

void pushThread(SafeStack<int>& s, int start, int count) {
    for (int i = start; i < start + count; ++i) {
        try {
            s.push(i);
        } catch (const std::exception& e) {
            std::cerr << "异常: " << e.what() << std::endl;
        }
    }
}

int main() {
    SafeStack<int> s(20); // 容量 20

    std::thread t1(pushThread, std::ref(s), 0, 10);
    std::thread t2(pushThread, std::ref(s), 10, 10);

    t1.join();
    t2.join();

    std::cout << "栈大小: " << s.size() << std::endl;
    std::cout << "栈顶: " << s.top() << std::endl;
    std::cout << "最小值: " << s.min() << std::endl;
    std::cout << "最大值: " << s.max() << std::endl;

    s.clear();
    std::cout << "清空后栈是否为空: " << std::boolalpha << s.empty() << std::endl;

    return 0;
}
